<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8"> <meta name="viewport" content="width=device-width">
    <title>方差</title>
    <meta name="viewport" content="width=device-width,initial-scale=1, shrink-to-fit=no">
    <!-- Bootstrap CSS -->
    <link rel="stylesheet"
          href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/css/bootstrap.min.css"
          integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk"
          crossorigin="anonymous">
    <link rel="stylesheet"
          href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/androidstudio.min.css">
<!--    <link rel="stylesheet" href="/web_template_css.css">-->
    <!-- this is highlight.js -->
    <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
    <script id="MathJax-script" async
            src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
    </script>
    <script  src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"
    integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
    integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/js/bootstrap.min.js"
    integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js"></script>
    <style>
      img{
        display: block;
        height: auto;
        max-width: 100%;
      }
    </style>
  </head>
  <body>
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
        <a class="navbar-brand" href="#">kvrmnks</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
          <ul class="navbar-nav">
            <li class="nav-item active">
              <a class="nav-link" href="./../../../../../index.html" target="_self">Home <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="./../../../../../blog.html">Blog</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="./../../../../../about.html">About</a>
            </li>
          </ul>
        </div>
      </nav>



    <div class='container'>
      <!--more-->

<p><img src="file://C:/Users/Kvrmnks/Documents/Gridea/post-images/1590903931832.png" alt="">
先咕掉题解, 只贴代码吧</p>

<pre><code class="language-cpp">#include&lt;bits/stdc++.h&gt;
using namespace std;
const int MOD = 1000000007;
const int MAXN = 1000005;
typedef long long ll;
int n,data[MAXN],inv[MAXN],fac[MAXN],ifac[MAXN];
int sum,qsum;
int comb(int n,int m){
    return (((ll)fac[n]*(ll)ifac[m])%MOD*(ll)ifac[n-m])%MOD;
}
int main(){
    scanf(&quot;%d&quot;,&amp;n);
    for(int i=1;i&lt;=n;i++)scanf(&quot;%d&quot;,data+i);
    inv[0]=inv[1]=fac[0]=ifac[0]=fac[1]=ifac[1]=1;
    for(int i=1;i&lt;=n;i++){
        sum = (sum+data[i])%MOD;
        qsum = (qsum + ((ll)data[i]*(ll)data[i])%MOD)%MOD;
    }
    for(int i=2;i&lt;=n+1;i++){
        inv[i]=((ll)(MOD-MOD/i)*inv[MOD%i])%MOD;
        fac[i] = ((ll)fac[i-1]*(ll)i)%MOD;
        ifac[i] = ((ll)ifac[i-1] * (ll)inv[i])%MOD;
    }
    int ans=0;
    for(int i=0;i&lt;n;i++){ans=(ans+((ll)comb(n-1,i)*(ll)inv[i+1])%MOD)%MOD;}
    ans=((ll)ans*(ll)qsum)%MOD;
    for(int i=1;i&lt;=n;i++){
        ll tmp = 0;
        tmp = (comb(n-1,i-1) * (ll)qsum)%MOD;
        if(i&gt;=2)
            tmp =(tmp + ((ll)comb(n-2,i-2)*(ll)((((ll)sum*(ll)sum)%MOD-qsum)%MOD+MOD)%MOD)%MOD)%MOD;
        tmp = (tmp * (ll)(inv[i]))%MOD;
        tmp = (tmp * (ll)(inv[i]))%MOD;
        ans = (ans - tmp)%MOD;
        ans = (ans + MOD)%MOD;
    }
    printf(&quot;%d&quot;,ans);
    return 0;
}

</code></pre>


    </div>
    <script>
      hljs.initHighlightingOnLoad()
    </script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/2.5.0/highlightjs-line-numbers.min.js"></script>
  <script>
      hljs.initHighlightingOnLoad();
      hljs.initLineNumbersOnLoad();
  </script>
  </body>
</html>